<template>
  <div>
    <h2 class="demo">姓名：{{ name }}</h2>
    <h2>age:{{ age }}</h2>
    <button @click="hi">点我传递名字给You</button>
  </div>
</template>

<script>
  import pubsub from 'pubsub-js'
  export default {
    name:'My',
    data(){
      return {
          name:'张三',
          age:20
      }
    },
    methods:{
      hi(){
        //发布消息
        pubsub.publish('hi',this.name)
      }
    }

  }
</script>

<style scoped>
  .demo{
    color: green;
  }
</style>
